//
//  NewCityProgramaCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/13.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

class NewCityProgramaCell: BaseTableViewCell {
    
    @IBOutlet weak var bgView: UIView!
    
    lazy var titleAndImage : [[String : String]] = {
        
        return [["title" : "附近商家","imageName" : "homePage8"],["title" : "鲸喜购","imageName" : "homePage1"],["title" : "游戏","imageName" : "homePage3"],["title" : "鲸币","imageName" : "homePage5"],["title" : "签到","imageName" : "homePage6"],["title" : "足迹","imageName" : "homePage7"]]
        
    }()


    lazy var collectionView : UICollectionView = {
        
        let collet = UICollectionView(frame:CGRect(x: 0, y: 0, width: KScreenW, height: 176), collectionViewLayout: ProgressFlowLayout())
        
        collet.dataSource = self
        
        collet.delegate = self
        
        collet.backgroundColor = UIColor.white
        
        collet.register(UINib(nibName: self.StringFromClass(classType: HomeCollectionCell.self), bundle: nil), forCellWithReuseIdentifier: HomeCollectionCell.identifer())
        
        return collet
    }()
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        
        contentView.addSubview(collectionView)
        
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        
    }
    
}




extension NewCityProgramaCell:UICollectionViewDataSource,UICollectionViewDelegate{
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        
        
            return titleAndImage.count

        
    }
    
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: HomeCollectionCell.identifer(), for: indexPath) as! HomeCollectionCell
        

            cell.dic = titleAndImage[indexPath.item]
            

        
        
        return cell
        
    }
    
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
 
            
        let  dic = titleAndImage[indexPath.item]
            
        
        switch dic["title"]! {
            
        case "附近商家":
            
            let temp = viewController() as! NewCityHomeVC
            
            let push = NearbyShopsVC()
            
            push.location = Location(lat: temp.latitude, long: temp.longitude)
            
            temp.navigationController?.pushViewController(push, animated: true)
            
        case "鲸喜购":
            
            viewController().navigationController?.pushViewController(SurpriseShopVC(), animated: true)
            
        case "活动":
            viewController().navigationController?.pushViewController(BusinessActivityVC(), animated: true)
        case "商城":
            
            let tabV = UIApplication.shared.keyWindow?.rootViewController as! TabBarController
            
            tabV.myTabBar.buttonOnClick(btn: tabV.myTabBar.secendBtn!)
            
        case "游戏":
            
            viewController().navigationController?.pushViewController(GameCenterController(), animated: true)
            
        case "鲸币":
            
            viewController().navigationController?.pushViewController(MyGoldController(), animated: true)
        case "签到":
            performIsLoginJump(aSelector: #selector(signVC), target: self)
        case "足迹":
            performIsLoginJump(aSelector: #selector(footPrintVC), target: self)
        default:
            QLPlusLine()
        }
        
        
    }
    
}


extension NewCityProgramaCell{
    
    
    func footPrintVC() {
        
        let settingVC  = FootPrintStoreVC()
        
        settingVC.navigationItem.title = "我的足迹"
        
        settingVC.urlStr = "mobile/index.php?c=member_goodsbrowse&a=browse_list"
        
        viewController().navigationController?.pushViewController(settingVC, animated: true)
        
        
        
    }
    
    
    
    func signVC() {
        
        let signVC  = UpLoadIconController()
        
        signVC.urlStr = HomeGloabeModel.golableModel.sign_url
        
        viewController().navigationController?.pushViewController(signVC, animated: true)
        
        
        
    }
    
    
    
    
    
    
}


